/*
 * $Id: QEOperator.m 248 2008-09-08 15:31:38Z jon $
 * Sleeper
 *
 * Created by Jon Gordon on 3/19/08
 * Copyright Jon Gordon.  All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining 
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to 
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#import "QEOperator.h"

#import "QECallsign.h"

@implementation QEOperator
- (id)init
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [self initWithCall:nil];
} // init

- (id)initWithCall:(NSString *)newCall
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    self = [super init];
    if (nil != self) {
        [self setCall:newCall];
    } // if
    return self;
} // initWithCall:

- (id)initWithCoder:(NSCoder *)coder
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    self = [super init];
    
    [self setCall:[coder decodeObjectForKey:@"OpCall"]];
    
    return self;
} // initWithCoder:

- (void)encodeWithCoder:(NSCoder *)coder
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    
    [coder encodeObject:[self call] forKey:@"OpCall"];
} // encodeWithCoder:

- (NSString *)call
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[call retain] autorelease];
} // call

- (void)setCall:(NSString *)newCall
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    if (call != newCall) {
        [call release];
        call = [newCall copy];
    } // if
} // setCall:

- (BOOL)validateCall:(id *)ioValue error:(NSError **)outError
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [QECallsign isValidBaseCallsign:ioValue error:outError];
} // validateCall:error:

- (NSString *)description
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [self call];
} // description

- (void)dealloc
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    [call release];
    [super dealloc];
} // dealloc

- (id)copyWithZone:(NSZone *)zone
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    QEOperator *newData = [[[self class] allocWithZone:zone]
                           initWithCall:[self call]];
    return newData;
} // copyWithZone:

- (unsigned int)hash
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[self call] hash];
} // hash

- (BOOL)isEqual:(id)anObject
{
    NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return ((self == anObject) ||
            [[self call] isEqual:[anObject call]]);
} // isEqual:
@end